(function () {
//同号工单
    var ghgd = {phone: location.href.substr(location.href.indexOf('=')+1)}
    var contentObj=document.getElementsByClassName("work-order")[0];
    console.log(ghgd)
    if(ghgd == null){
        $.modal.msgWarning('请输入电话号码');
        return;
    }
    // if(!checkPhone(ghgd)){
    //     $.modal.alertError("无效电话号码");
    //     contentObj.innerHTML = '没有数据';
    //     return;
    // }
    $.ajax({
        url: "/api/bd/workList",
        data: ghgd,
        type: "POST",
        dataType: "json",
        beforeSend: function () {
            $('#loading').modal('show');
        },
        complete: function () {
            $('#loading').modal('hide');
        },
        success: function (data) {
            console.log(data)
            $('#loading').modal('hide');
            if (data.totalCount == 0) {
                contentObj.innerHTML = '没有数据';
            } else {
                //调用渲染表格页面
                var arr = data.data;
                var isHtml = "";
                isHtml += '<div class="col-sm-12 entiretyjackPerLine">'
                isHtml += '<div class="entiretyjackPerLine-title">'
                isHtml += '<div style="width: 400px"><h4>主题:' +'['+arr[0].appeal_type + ']'+'</h4></div>'
                isHtml += '<div class="entiretyjackPerLine-title-aSpan"><a class="entiretyjackPerLine-title-a">收起</a><span class="gl glyphicon glyphicon-chevron-up"></span></div>'
                isHtml += '</div>'
                isHtml += '<div class="jackPerLine-list">'
                isHtml += '<ul class="timeline-list">'
                for (var j = 0; j < arr.length; j++) {
                    isHtml += '<li class="timeline-item">'
                    isHtml += '<div class="timeline-item_tail"></div>'
                    isHtml += '<div class="timeline-item_node"></div>'
                    isHtml += '<div class="timeline-item_wrapper ">'
                    isHtml += '<div class="timeline-item_timestamp">'
                    isHtml += '<div style="width: 300px"><a href="javascript:void(0)" onclick="parent.telDetail(1,'+arr[j].id+')">' + arr[j].publisher+'['+arr[j].appeal_type + ']'+arr[j].customized_event_type+'</a></div>'
                    isHtml += '<div class="col-sm-12 work-box-top-box" style="padding: 0">'
                    isHtml += '<div class="col-sm-5">'
                    isHtml += '<div class="work-box-buttom-time">' + arr[j].insert_time + '</div>'
                    isHtml += '</div>'
                    isHtml += '<div class="col-sm-5 work-box-buttom" style="padding: 0">'
                    isHtml += '<div class="">部门:' + arr[j].assigner + '</div>'
                    isHtml += '</div>'
                    isHtml += '<div class="col-sm-2" style="padding: 0">'
                    isHtml += '<button type="button" class="btn btn-sm btn-primary" style="color: #206ef7;background-color: white;" onclick="copyTelData(1,'+arr[j].id+')">一键复制';
                    isHtml += '</button>'
                    isHtml += '</div>'
                    isHtml += '</div>'
                    isHtml += '<div class="work-box" style="margin-top: 10px;line-height:20px">'
                    isHtml += '<div class="col-sm-12 work-box-class" style="margin: 0;padding: 0" >'
                    isHtml += '<div style="display: flex">'
                    isHtml += '<div class="work-box-class-font">'
                    isHtml += '<div class="entiretyjackPerLine-title-aS"><a class="entiretyjackPerLine-title-aa">展开</a><span class="glyphi glyphicon glyphicon-chevron-down"></span>'
                    isHtml += '</div>'
                    // isHtml += '<span style="color: #BABBBD">投诉:</span>'
                    isHtml += '<span class="work-box-copy" onclick="parent.telDetail(1,'+arr[j].id+')"  style="font-weight: normal;cursor:pointer">' + arr[j].parse_text + '</span>'
                    isHtml += '</div>'
                    isHtml += '</div>'
                    isHtml += '<div class="col-sm-12 work-box-hover"'
                    isHtml += 'style="padding: 0;margin-top: 15px">'
                    // isHtml += '<a  style="margin-right: 15px" href="javascript:void(0)" onclick="parent.telDetail(1,'+arr[j].id+')" >详情</a>'
                    // isHtml += '<a  style="margin-right: 15px" href="javascript:void(0)" onclick="parent.telDetail(1,23789943)" >详情</a>'
                    // isHtml += '<a class="work-buttom">一键复制</a>'
                    isHtml += '</div>'
                    isHtml += '</div>'
                    isHtml += '</div>'
                    isHtml += '</div>'
                    isHtml += '</div>'
                    isHtml += '</li>'
                }
                isHtml += '</ul>'
                isHtml += '</div>'
                isHtml += '</div>'
                contentObj.innerHTML = isHtml;
                //主题张开
                $(".entiretyjackPerLine-title-aSpan").each(function (index, item) {
                    $(this).bind("click", function () {
                        console.log(index);
                        if ($('.entiretyjackPerLine-title-a')[index].text == '收起') {
                            $('.entiretyjackPerLine-title-a')[index].text = '展开';
                            $($(".gl")[index]).removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
                            $($('.jackPerLine-list')[index]).fadeOut();
                        } else if ($('.entiretyjackPerLine-title-a')[index].text == '展开') {
                            $('.entiretyjackPerLine-title-a')[index].text = '收起';
                            $($(".gl")[index]).removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
                            $($('.jackPerLine-list')[index]).fadeIn();
                        }
                    })
                });
                //类容张开
                $(".entiretyjackPerLine-title-aS").each(function (index, item) {
                    $(this).bind("click", function () {
                        if ($('.entiretyjackPerLine-title-aa')[index].text == '收起') {
                            $('.entiretyjackPerLine-title-aa')[index].text = '展开';
                            $($(".glyphi")[index]).removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
                            $($('.work-box-class-font')[index]).css('-webkit-line-clamp', '');
                        } else if ($('.entiretyjackPerLine-title-aa')[index].text == '展开') {
                            $('.entiretyjackPerLine-title-aa')[index].text = '收起';
                            $($(".glyphi")[index]).removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
                            $($('.work-box-class-font')[index]).css('-webkit-line-clamp', '999');
                        }
                    })
                });
            }
        }
    });
})()
function copyTelData(type,id){
    $.ajax({
        type: "GET",
        url:  "/system/lookup/sameTelOrderDetail/"+id,
        error: function (request) {
            $.modal.alertError("系统错误"+request);
        },
        success: function (data) {
            console.log(data)
            parent.copy(type,data);
        }
    });
}

function checkPhone(mobile) {
    var tel = /^0\d{2,3}-?\d{7,8}$/;
    var phone = /^[1][3,4,5,6.7,8,9][0-9]{9}$/
    if(mobile.phone.length == 11){//手机号码
        if(phone.test(mobile.phone)) {
            console.log(mobile.phone);
            return true;
        }
    }else if(mobile.phone.length == 12 && mobile.indexOf("-") != -1 ){//电话号码
        if(tel.test(mobile.phone)) {
            console.log(mobile.phone);
            return true;
        }
    }
    console.log('请输入有效的号码！');
    return false;

}
